package com.qf.face.controller;

import com.qf.base.face.dto.FaceDTO;
import com.qf.base.result.R;
import com.qf.base.utils.FileBase64Util;
import com.qf.face.util.BaiduUtil;
import com.qf.face.util.FaceUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.awt.image.BufferedImage;

import static com.qf.base.utils.FileBase64Util.*;

@RestController
@RequestMapping("/face")
public class FaceController {
    @PostMapping("/search")
    public R searchFace(@RequestBody FaceDTO faceDTO){
        String base64=faceDTO.getBase64();
        //把base64还原为图片
        BufferedImage image = base64Image(base64);
        //找图片中有没有脸
        BufferedImage face = FaceUtil.haveFace(image);
        if (face!=null){
            base64= image2Base64(face);
            Long id = BaiduUtil.whoAreYou(base64, 0);
            return  R.ok(200,"识别成功").setResult(id);
        }

        return R.error(500,"识别失败");
    }
}
